import django_filters

from orders.models import OrderInfo
from vouchers.models import AliDiscountCouponInfo, CustomizeActivityFlipCARDS
from goods.models import Goods, LaunchedGoods
from users.models import Level
from merchants.models import Merchant
from activities.models import ActivityData, PointRecord


class OrderInfoFilter(django_filters.rest_framework.FilterSet):
    '''订单过滤'''

    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')

    class Meta:
        model = OrderInfo
        fields = ('state', )


class AliDiscountCouponInfoFilter(django_filters.rest_framework.FilterSet):
    '''支付宝活动过滤'''

    status = django_filters.BaseInFilter(field_name='status', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponInfo
        fields = ('status', )


class GoodsFilter(django_filters.rest_framework.FilterSet):
    '''商品过滤'''

    alidiscountcoupon_id = django_filters.BaseInFilter(field_name='alidiscountcoupongoodsavailable__alidiscountcoupon_id', lookup_expr='in')
    # level_id = django_filters.BaseInFilter(field_name='launchedgoods__level_id', lookup_expr='in')
    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')
    price_min = django_filters.NumberFilter(field_name="price", lookup_expr='gte')
    price_max = django_filters.NumberFilter(field_name="price", lookup_expr='lte')

    class Meta:
        model = Goods
        fields = ('alidiscountcoupon_id', 'merchant_id', 'price_min', 'price_max')


class LaunchedGoodsFilter(django_filters.rest_framework.FilterSet):
    '''商品过滤'''

    alidiscountcoupon_id = django_filters.BaseInFilter(field_name='alidiscountcoupongoodsavailable__alidiscountcoupon_level_id', lookup_expr='in')
    level_id = django_filters.BaseInFilter(field_name='level_id', lookup_expr='in')
    merchant_id = django_filters.BaseInFilter(field_name='goods__merchant_id', lookup_expr='in')

    class Meta:
        model = LaunchedGoods
        fields = ('alidiscountcoupon_id', 'level_id', 'merchant_id')


class LevelFilter(django_filters.rest_framework.FilterSet):
    '''层级过滤'''

    city_id = django_filters.BaseInFilter(field_name='city_id', lookup_expr='in')
    prov_id = django_filters.BaseInFilter(field_name='prov_id', lookup_expr='in')
    # goods_id = django_filters.BaseInFilter(field_name='launchedgoods__goods_id', lookup_expr='in')

    class Meta:
        model = Level
        fields = ('prov_id', 'city_id')


class MerchantFilter(django_filters.rest_framework.FilterSet):
    '''商户过滤'''

    category_id = django_filters.BaseInFilter(field_name='goods__category_id', lookup_expr='in')
    alidiscountcoupon_id = django_filters.BaseInFilter(field_name='alidiscountcouponmerchant__alidiscountcoupon_id', lookup_expr='in')

    class Meta:
        model = Merchant
        fields = ('category_id',)


class ActivityDataFilter(django_filters.rest_framework.FilterSet):

    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')
    activity_level_id = django_filters.BaseInFilter(field_name='activity_level_id', lookup_expr='in')

    class Meta:
        model = ActivityData
        fields = ('state', 'activity_level_id')


class PointRecordFilter(django_filters.rest_framework.FilterSet):

    activity_data_id = django_filters.BaseInFilter(field_name='activity_data_id', lookup_expr='in')

    class Meta:
        model = PointRecord
        fields = ('activity_data_id', )


class CustomizeActivityFlipCARDSFilter(django_filters.rest_framework.FilterSet):

    open_status = django_filters.BaseInFilter(field_name='open_status', lookup_expr='in')

    class Meta:
        model = CustomizeActivityFlipCARDS
        fields = ('open_status', )